package ThreadTest_p.t3_useJoin.v1;

import java.util.concurrent.ExecutionException;
import java.util.concurrent.FutureTask;

public class UseJoinn {
    public static void main(String[] args) throws InterruptedException, ExecutionException {
        Job job = new Job();
        Job2 job2 = new Job2();
        Thread worker = new Thread(job);
        // worker.run(); // 主线程执行
        //Thread t2 = new Thread((Runnable) job2);
        FutureTask<Integer> ft = new FutureTask<>(job2);
        Thread t3 = new Thread(ft);
        t3.start();
        Integer i = ft.get();
        System.out.println("job2线程执行返回的结果: " + i);
        worker.start();
        worker.join(); // 主线程阻塞，等待子线程结束
        System.out.println("主线程继续执行");
    }
}
